package com.tbit.uqbike.compalint.enums;

import java.util.Objects;

/**
 * 客诉处理状态枚举
 *
 * @author <a href="mailto:zhang.zhiliang@tbit.com.cn">Zhang ZhiLiang</a>
 * @version 1.0
 * @see <a href="http://adsl1.tbit.com.cn:21490/pages/viewpage.action?pageId=82182491">订单号规范</a>
 * @since 2025/2/14
 */
public enum ComplaintStatusEnum {
    NEW("未处理",0),
    PROCESSING("处理中",1),
    FINISH("已完成",2),
    ALL("全部",3),
    UNKNOWN("未知状态",-1)
    ;

    private final String name;
    private final Integer code;

    public String getName() {
        return name;
    }

    public Integer getCode() {
        return code;
    }

    ComplaintStatusEnum(String name, Integer code) {
        this.name = name;
        this.code = code;
    }

    /**
     * 更具编码获取状态
     * @param code
     * @return
     */
    public static ComplaintStatusEnum getByCode(Integer code){
        for (ComplaintStatusEnum value : ComplaintStatusEnum.values()) {
            if (Objects.equals(value.getCode(),code)){
                return value;
            }
        }
        return UNKNOWN;
    }

    /**
     * 将微信状态归纳为平台状态
     * @param status 微信返回状态码
     * @return 枚举值
     */
    public static ComplaintStatusEnum getComplaintEnumByWechat(String status){
        switch (status){
            case "PENDING" :
                return NEW;
            case "PROCESSING" :
                return PROCESSING;
            case "PROCESSED" :
                return FINISH;
            default :
                return UNKNOWN;
        }
    }

    /**
     * 将汇付状态归纳为平台状态
     * @param status 微信返回状态码
     * @return 枚举值
     */
    public static ComplaintStatusEnum getComplaintEnumByAdapay(String status){
        switch (status){
            case "PENDING" :
                return NEW;
            case "PROCESSING" :
                return PROCESSING;
            case "PROCESSED" :
                return FINISH;
            default :
                return UNKNOWN;
        }
    }

    /**
     * 将汇付状态归纳为平台状态
     * @param status 微信返回状态码
     * @return 枚举值
     */
    public static ComplaintStatusEnum getComplaintEnumByZFB(String status){
        switch (status){
            case "MERCHANT_PROCESSING" :
                return NEW;
            case "FINISHED" :
            case "PLATFORM_FINISH" :
            case "CANCELLED" :
            case "CLOSED" :
                return FINISH;
            case "PLATFORM_PROCESSING" :
            case "MERCHANT_FEEDBACKED" :
                return PROCESSING;
            default :
                return UNKNOWN;
        }
    }
}
